package com.fxp.project.jiuselu.web.models.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fxp.project.jiuselu.commons.constant.ConstantCode;
import com.fxp.project.jiuselu.commons.exceptions.JiuLuException;
import com.fxp.project.jiuselu.commons.exceptions.ParamException;
import com.fxp.project.jiuselu.commons.utils.RandomUtils;
import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.business.v1.request.order.ReqCancelOrder;
import com.fxp.project.jiuselu.web.business.v1.request.order.ReqOrderCart;
import com.fxp.project.jiuselu.web.business.v1.request.order.ReqOrderConfirmReceipt;
import com.fxp.project.jiuselu.web.business.v1.request.order.ReqOrderQuickly;
import com.fxp.project.jiuselu.web.models.commission.service.JslCommissionService;
import com.fxp.project.jiuselu.web.models.common.entity.JslLogisticCompany;
import com.fxp.project.jiuselu.web.models.common.mapper.JslLogisticCompanyMapper;
import com.fxp.project.jiuselu.web.models.config.entity.JslConfig;
import com.fxp.project.jiuselu.web.models.config.mapper.JslConfigMapper;
import com.fxp.project.jiuselu.web.models.coupon.entity.JslCoupon;
import com.fxp.project.jiuselu.web.models.coupon.entity.JslCouponUseList;
import com.fxp.project.jiuselu.web.models.coupon.entity.JslUserCoupon;
import com.fxp.project.jiuselu.web.models.coupon.mapper.JslCouponMapper;
import com.fxp.project.jiuselu.web.models.coupon.mapper.JslCouponUseListMapper;
import com.fxp.project.jiuselu.web.models.coupon.mapper.JslUserCouponMapper;
import com.fxp.project.jiuselu.web.models.coupon.vo.JslUserCouponVo;
import com.fxp.project.jiuselu.web.models.fare.entity.JslUserFareApplied;
import com.fxp.project.jiuselu.web.models.fare.entity.JslUserFareOrderApply;
import com.fxp.project.jiuselu.web.models.fare.mapper.JslUserFareAppliedMapper;
import com.fxp.project.jiuselu.web.models.fare.mapper.JslUserFareOrderApplyMapper;
import com.fxp.project.jiuselu.web.models.goods.entity.JslGoodsSalePrices;
import com.fxp.project.jiuselu.web.models.goods.mapper.JslGoodsAttrMapper;
import com.fxp.project.jiuselu.web.models.goods.mapper.JslGoodsMapper;
import com.fxp.project.jiuselu.web.models.goods.vo.GoodsAttrVo;
import com.fxp.project.jiuselu.web.models.goods.vo.GoodsVo;
import com.fxp.project.jiuselu.web.models.order.entity.*;
import com.fxp.project.jiuselu.web.models.order.mapper.*;
import com.fxp.project.jiuselu.web.models.order.service.IJslLogisticAreaService;
import com.fxp.project.jiuselu.web.models.order.service.IJslOrderService;
import com.fxp.project.jiuselu.web.models.order.service.IJslUserBalanceService;
import com.fxp.project.jiuselu.web.models.order.vo.JslLogisticAreaVo;
import com.fxp.project.jiuselu.web.models.order.vo.JslOrderArrearsVo;
import com.fxp.project.jiuselu.web.models.order.vo.JslOrderVo;
import com.fxp.project.jiuselu.web.models.order.vo.UserOrderPageVo;
import com.fxp.project.jiuselu.web.models.shareprofit.entity.JslShareProfitRecord;
import com.fxp.project.jiuselu.web.models.shareprofit.service.IJslShareProfitRecordService;
import com.fxp.project.jiuselu.web.models.user.entity.JslUser;
import com.fxp.project.jiuselu.web.models.user.entity.JslUserAddress;
import com.fxp.project.jiuselu.web.models.user.entity.JslUserExtend;
import com.fxp.project.jiuselu.web.models.user.mapper.JslUserAddressMapper;
import com.fxp.project.jiuselu.web.models.user.mapper.JslUserExtendMapper;
import com.fxp.project.jiuselu.web.models.user.mapper.JslUserMapper;
import com.fxp.project.jiuselu.web.models.user.service.IJslUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author Jason.Wang
 * @since 2021-11-17
 */
@Service
public class JslOrderServiceImpl extends ServiceImpl<JslOrderMapper, JslOrder> implements IJslOrderService {
    @Autowired
    JslOrderMapper jslOrderMapper;
    @Autowired
    JslOrderGoodsMapper jslOrderGoodsMapper;
    @Autowired
    JslUserCouponMapper jslUserCouponMapper;
    @Autowired
    JslCartMapper jslCartMapper;
    @Autowired
    JslGoodsMapper jslGoodsMapper;
    @Autowired
    JslGoodsAttrMapper jslGoodsAttrMapper;
    @Autowired
    JslUserMapper jslUserMapper;
    @Autowired
    JslUserAddressMapper jslUserAddressMapper;
    @Autowired
    JslUserExtendMapper jslUserExtendMapper;
    @Autowired
    JslLogisticAreaMapper jslLogisticAreaMapper;
    @Autowired
    JslOrderArrearsMapper jslOrderArrearsMapper;
    @Autowired
    JslConfigMapper jslConfigMapper;
    @Autowired
    IJslUserService jslUserService;
    @Autowired
    JslLogisticCompanyMapper jslLogisticCompanyMapper;
    @Autowired
    JslUserFareOrderApplyMapper jslUserFareOrderApplyMapper;
    @Autowired
    JslUserFareAppliedMapper jslUserFareAppliedMapper;
    @Autowired
    IJslUserBalanceService jslUserBalanceService;
    @Autowired
    JslCommissionService jslCommissionService;
    @Autowired
    JslCouponMapper jslCouponMapper;
    @Autowired
    JslCouponUseListMapper jslCouponUseMapper;

    /**
     * getGoodsCurrentPrice: 获取当前商品的价格信息<br/>
     *
     * @param goodsSalePricesList
     * @param goodsWeight
     * @return
     * @author Jason.Wang
     * @date 2022/3/28 16:22
     */
    BigDecimal getGoodsCurrentPrice(List<JslGoodsSalePrices> goodsSalePricesList, BigDecimal goodsWeight) {
//        if (CollectionUtils.isEmpty(goodsSalePricesList)) {
//            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "规格价格设置有误");
//        }
//        JslGoodsSalePrices goodsSalePrices = goodsSalePricesList.stream().filter(item -> {
//            if (item.getMax().compareTo(BigDecimal.ZERO) == 0 && item.getMin().compareTo(goodsWeight) < 0) {
//                return true;
//            } else {
//                return item.getMin().compareTo(goodsWeight) <= 0 && item.getMax().compareTo(goodsWeight) > 0;
//            }
//        }).findFirst().orElse(null);
//        if (null == goodsSalePrices) {
//            goodsSalePrices = goodsSalePricesList.stream().max(Comparator.comparing(JslGoodsSalePrices::getMax)).get();
//            return goodsSalePrices.getPrice();
//        } else return goodsSalePrices.getPrice();

        if (CollectionUtils.isEmpty(goodsSalePricesList)) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "规格价格设置有误");
        }
        JslGoodsSalePrices goodsSalePrices = null;
        //区间判断
        for (JslGoodsSalePrices item : goodsSalePricesList) {
            BigDecimal min = item.getMin();
            BigDecimal max = item.getMax();

            if (goodsWeight.compareTo(min) == 0 || goodsWeight.compareTo(max) == 0) {
                goodsSalePrices = item;
                break;
            }

            if (goodsWeight.compareTo(min) == 1 && goodsWeight.compareTo(max) == -1) {
                goodsSalePrices = item;
                break;
            }
        }

        if (null == goodsSalePrices) {
            goodsSalePrices = goodsSalePricesList.stream().max(Comparator.comparing(JslGoodsSalePrices::getMax)).get();
            return goodsSalePrices.getPrice();
        } else return goodsSalePrices.getPrice();


    }

    @Autowired
    private IJslLogisticAreaService jslLogisticAreaService;

    /**
     * saveUserOrderByUserId:购物车<br/>
     *
     * @param reqOrderCart
     * @param userId
     * @return
     * @author Kai.wj
     * @date 2021/11/18 11:28
     */
    @Override
    @Transactional
    public Object saveUserOrderByUserId(ReqOrderCart reqOrderCart, Long userId) {
        //订单支付总金额
        BigDecimal totalAmount = new BigDecimal("0");
        BigDecimal orderAmount = new BigDecimal("0");

        // 创建订单对象
        JslOrder jslOrder = new JslOrder();
        // 下单人
        jslOrder.setUserId(userId);
        // 订单状态;0：未完结 1：已完结
        jslOrder.setOrderStatus(0);
        // 订单代发货
        jslOrder.setLogisticStatus(0);
        // 支付状态;0：未支付 1：支付完成 2：已支付预付款
        jslOrder.setPayStatus(0);
        // 下单时间
        jslOrder.setAddTime(LocalDateTime.now());
        // 是否分成
        jslOrder.setIsDistribute(0);
        // 用户订单备注
        jslOrder.setUserNote(reqOrderCart.getUserNote());

        List<JslCart> cartList = jslCartMapper.selectBatchIds(reqOrderCart.getCartIds());
        if (CollectionUtils.isEmpty(cartList)) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前没有商品提交，请到购物车重试");
        }


        // set用户优惠卷
        JslUserCouponVo jslUserCouponVo = null;
        if (null != reqOrderCart.getCouponId() && reqOrderCart.getCouponId() != 0) {
            //如果查询的list为0 提示没有对应的优惠价
            List<JslUserCouponVo> jslUserCouponVos = jslUserCouponMapper.selectJslUserCouponVoListBytow(reqOrderCart.getCId(), userId);
            if (jslUserCouponVos.size() == 0) {
                throw new JiuLuException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前选择优惠券不存在或已过期");
            } else {
                jslUserCouponVo = jslUserCouponVos.get(0);
            }
        }

        // 查询当前用户提交的地址信息
        JslUserAddress jslUserAddress =
                jslUserAddressMapper.selectJslUserAddressByUserIdWithAddressId(userId, reqOrderCart.getAddressId());
        if (null == jslUserAddress) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前选择的地址不存在，请重新提交");
        }
        jslOrder.setConsignee(jslUserAddress.getName());
        jslOrder.setCountry(0);
        jslOrder.setProvinceId(jslUserAddress.getProvinceId());
        jslOrder.setProvinceName(jslUserAddress.getProvinceName());
        jslOrder.setCityId(jslUserAddress.getCityId());
        jslOrder.setCityName(jslUserAddress.getCityName());
        jslOrder.setDistrictId(jslUserAddress.getDistrictId());
        jslOrder.setDistrictName(jslUserAddress.getDistrictName());
        jslOrder.setAddress(jslUserAddress.getAddress());
        jslOrder.setPhone(jslUserAddress.getPhone());
        // 当前产品的邮费金额
        jslOrder.setLogisticPrice(BigDecimal.ZERO);
        AtomicBoolean freeShipping = new AtomicBoolean(false);
        AtomicReference<Long> logisticId = new AtomicReference<>(0L);
        BigDecimal goodsWeight = BigDecimal.ZERO;
        List<JslOrderGoods> jslOrderGoodsList = new ArrayList<>();
        jslOrder.setGoodsPrice(BigDecimal.ZERO);
        jslOrder.setTotalAmount(BigDecimal.ZERO);
        // 循环遍历当前购车中的对象
        cartList.forEach(cart -> {
            // 查询当前商品信息
            GoodsVo goodsVo = jslGoodsMapper.selectGoodsVoByGoodsId(cart.getGoodsId());
            if (null == goodsVo || !goodsVo.getGoodsStatus().equals(1)) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前提交订单商品不存在或已下架");
            }
            // 查询当前商品规格信息
            GoodsAttrVo goodsAttrVo = jslGoodsAttrMapper.selectGoodsAttrVoByGoodsAttrId(cart.getAttrId());
            if (null == goodsAttrVo) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前提交订单商品不存在或已下架");
            }
            // 检查当前规格的库存信息
            if (goodsAttrVo.getStoreCount() - cart.getGoodsNum() < 0) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前商品库存不足，请重新选择");
            }
            // 计算当前的商品的总重量
            BigDecimal goodsTotalWeight = BigDecimal.ZERO;

            freeShipping.set(goodsVo.getFreeShipping() == 1);
            // 当前产品不包邮
            if (null != goodsVo.getFreeShipping() && goodsVo.getFreeShipping() == 0) {
                logisticId.set(goodsVo.getLogisticId());
            }
            // 计算出来当前商品的总重量信息
            System.err.println(goodsAttrVo.getAttrWeight());
            System.err.println(cart.getGoodsNum());
            System.err.println(goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(cart.getGoodsNum())));
            //计算商品总重量，规格重量*数量
            goodsWeight.add(goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(cart.getGoodsNum())));
            // 订单中的商品信息
            JslOrderGoods jslOrderGoods = new JslOrderGoods();
            // 商品Id
            jslOrderGoods.setGoodsId(goodsVo.getGoodsId());
            // 商品名称
            jslOrderGoods.setGoodsName(goodsVo.getGoodsName());
            // 商品规格Id
            jslOrderGoods.setGoodsAttrId(goodsAttrVo.getAttrId());
            // 商品规格名称
            jslOrderGoods.setGoodsAttrName(goodsAttrVo.getAttrName());
            // 商品购买数量
            jslOrderGoods.setGoodsNum(cart.getGoodsNum());
            jslOrderGoods.setGoodsAttrImage(goodsVo.getGoodsImages());
            // 全款订单
            jslOrder.setOrderId(String.format("QK%s", RandomUtils.getOrderNo()));
            // 配置当前商品全额购买的金额信息
            if (goodsAttrVo.getSalePricesList().size() > 0) {//有
                jslOrderGoods.setGoodsPrice(getGoodsCurrentPrice(goodsAttrVo.getSalePricesList(), goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(cart.getGoodsNum()))));
            } else {
                jslOrderGoods.setGoodsPrice(goodsAttrVo.getAttrPrice());
            }
            int i = goodsAttrVo.getStoreCount() - jslOrderGoods.getGoodsNum();
            goodsAttrVo.setStoreCount(i);
            jslGoodsAttrMapper.updateById(goodsAttrVo);
            jslOrder.setOrderType(0);
            //购物车计算出商品的基本价格  设置商品的总价 商品规格单价 * 商品数量 * 重量
            if (jslOrder.getTotalAmount() == BigDecimal.ZERO) {
                jslOrder.setTotalAmount(jslOrderGoods.getGoodsPrice().multiply(goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(cart.getGoodsNum()))));
            } else {
                jslOrder.setTotalAmount(jslOrder.getTotalAmount().add(jslOrderGoods.getGoodsPrice().multiply(goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(cart.getGoodsNum())))));

            }
            // 订单号
            jslOrderGoods.setOrderId(jslOrder.getOrderId());
            jslOrderGoodsList.add(jslOrderGoods);
            System.out.println("商品信息");
        });
        jslOrder.setGoodsPrice(reqOrderCart.getPrice());
        //购物车基本总价
        totalAmount = jslOrder.getTotalAmount();

        // 查询出当前商品配置的运费信息
        JslLogisticAreaVo jslLogisticAreaVo =
                jslLogisticAreaMapper.selectJslLogisticAreaVoByLogisticIdWithAreaId(logisticId.get(),
                        jslUserAddress.getProvinceId());
//        if (null == jslLogisticAreaVo) {
//            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前商品不属于配送区域，请联系客服解决");
//        }

        List<String> goodIds = new ArrayList<>();
        for (JslCart jslCart : cartList) {
            Long goodsId = jslCart.getGoodsId();
            goodIds.add(goodsId.toString());
        }
        //查询当前用户在jsl_cart购物车表中type=1的某个商品,type=0为样品
        List<JslCart> jslCarts = jslCartMapper.selectList(new QueryWrapper<JslCart>().lambda().eq(JslCart::getUserId, Objects.requireNonNull(BaseController.getUser()).getUserId()).eq(JslCart::getType,"0"));
        //运费
//        BigDecimal logistic = jslLogisticAreaService.getMoney(jslLogisticAreaVo, goodIds, jslCarts);

        // 物流的信息
//        jslOrder.setLogisticName(jslLogisticAreaVo.getCompanyName());
//        jslOrder.setLogisticCode(jslLogisticAreaVo.getCompanyCode());
//                // 计算当前产品的运费信息，计算当前的重量向上取整
//                //截取weightprice字符串,拿到金额
//                BigDecimal weight = reqOrderCart.getWeight();
//                String weightprice = jslLogisticAreaVo.getWeightprice();
//                //   String weightprice=wp.replace("\\","").replace("[","").replace("]","");
//                JSONArray object = JSON.parseArray(weightprice);
//                List<JslArea> list = JSONObject.parseArray(object.toJSONString(), JslArea.class);
//                for (JslArea l : list) {
//                    BigDecimal maxWeight = l.getMaxWeight();
//                    BigDecimal mixWeight = l.getMixWeight();
//                    BigDecimal money = l.getMoney();
//                    if (mixWeight.compareTo(weight) == -1 && maxWeight.compareTo(weight) == 1) {
//                        BigDecimal f = weight.multiply(money);
//                        jslOrder.setLogisticPrice(f);
//                    } else if (maxWeight.compareTo(weight) == 0) {
//                        BigDecimal f = weight.multiply(money);
//                        jslOrder.setLogisticPrice(f);
//                    } else if (mixWeight.compareTo(weight) == 0) {
//                        BigDecimal f = weight.multiply(money);
//                        jslOrder.setLogisticPrice(f);
//                    }
//                }
        jslOrder.setLogisticPrice(reqOrderCart.getLogisticPrice());
        totalAmount = totalAmount.add(jslOrder.getLogisticPrice());
        /**
         * 计算优惠券抵扣金额，当前优惠券的使用条件为支付金额需要大于等于优惠券使用条件
         */
        if (null != jslUserCouponVo && -1 != totalAmount.compareTo(jslUserCouponVo.getAmount())) {
            if (jslUserCouponVo.getCategory() == 1) {
                BigDecimal remAmount = jslUserCouponVo.getRemAmount();
                /*JslCoupon jslCoupon = jslCouponMapper.selectById(reqOrderCart.getCouponId());
                BigDecimal amount = jslCoupon.getAmount();
                BigDecimal remAmount1 = jslUserCouponVo.getRemAmount();
                BigDecimal scale = jslUserCouponVo.getDiscount().multiply(new BigDecimal("0.01"));
                BigDecimal discount = totalAmount.multiply(scale);
                jslUserCouponVo.setDiscount(discount);
                //判断代金券是否有余额
                if (remAmount1.compareTo(new BigDecimal("0.00")) != 0) {
                    //如果订单金额比代金券余额大
                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                    jslOrder.setCouponPrice(remAmount1);
                    jslUserCouponVo.setStatus(1);
                } else {
                    //代金券余额为空时
                    BigDecimal remAmount = amount.subtract(discount);
                    jslUserCouponVo.setRemAmount(remAmount);
                    if (remAmount.compareTo(new BigDecimal("0.00")) <= 0) {
                        jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                        jslUserCouponVo.setStatus(1);
                    }
                    jslOrder.setCouponPrice(discount);
                }*/
                //订单金额比代金券余额大
                if(totalAmount.compareTo(remAmount) > 0){
//                    totalamount = totalamount.subtract(remAmount);
                    jslOrder.setCouponPrice(remAmount);
                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                    jslUserCouponVo.setStatus(1);
                } else if(totalAmount.compareTo(remAmount) == 0){
//                    totalamount =new BigDecimal("0.00");
                    jslOrder.setCouponPrice(remAmount);
                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                    jslUserCouponVo.setStatus(1);
                } else if(totalAmount.compareTo(remAmount) < 0){
                    jslOrder.setCouponPrice(totalAmount);
//                    totalamount = new BigDecimal("0.00");
                    jslUserCouponVo.setStatus(3);
                    jslUserCouponVo.setRemAmount(remAmount.subtract(totalAmount));
                }

            }
            jslUserCouponVo.setOrderId(jslOrder.getOrderId());
            jslUserCouponVo.setUseTime(LocalDateTime.now());
            jslUserCouponVo.setUpdateTime(LocalDateTime.now());
            JslCouponUseList couponUseList=new JslCouponUseList();

            if (jslUserCouponVo.getCategory() == 0) {
                jslUserCouponVo.setStatus(1);
                jslOrder.setCouponPrice(jslUserCouponVo.getDiscount());
                couponUseList.setOrderId(jslOrder.getOrderId());
                couponUseList.setUserId(userId);
                couponUseList.setCouponId(jslUserCouponVo.getCouponId());
                couponUseList.setUserCouponId(jslUserCouponVo.getId());
                jslCouponUseMapper.insert(couponUseList);
            }

            if(jslUserCouponVo.getRemAmount().compareTo(new BigDecimal("0.00"))>=0  && jslUserCouponVo.getCategory()==1){
                couponUseList.setOrderId(jslOrder.getOrderId());
                couponUseList.setUserId(userId);
                couponUseList.setCouponId(jslUserCouponVo.getCouponId());
                couponUseList.setUserCouponId(jslUserCouponVo.getId());
                jslCouponUseMapper.insert(couponUseList);
            }

            jslUserCouponMapper.updateUserCouponVo(jslUserCouponVo);
            //减去优惠价的价格
            jslOrder.setTotalAmount(totalAmount);
//            jslOrder.setTotalAmount(
//                    jslOrder.getGoodsPrice());
            //    jslUserCouponMapper.updateById(jslUserCouponVo);
        } else {
            jslOrder.setCouponPrice(BigDecimal.ZERO);
        }
        // 计算当前需要付款的金额，并设置保留两位小数
        // 当前订单的总金额 商品金额  - 优惠券金额 + 邮费金额

        totalAmount = totalAmount.subtract(jslOrder.getCouponPrice());
        jslOrder.setTotalAmount(totalAmount);
        // 当前需要付款的金额
        jslOrder.setOrderAmount(totalAmount);

        JslOrderArrears jslOrderArrears = new JslOrderArrears();
        jslOrderArrears.setArrearsId(String.format("%s%d", jslOrder.getOrderId(), 1));
        jslOrderArrears.setOrderId(jslOrder.getOrderId());
        jslOrderArrears.setArrearsPercent(jslOrder.getOrderPercent());
        jslOrderArrears.setPayStatus(0);
        jslOrderArrears.setCreateTime(LocalDateTime.now());

        if (jslOrderArrears.getArrearsPercent() == null) {
            jslOrderArrears.setArrearsPercent(0);
        }
        JslUser jslUser = jslUserMapper.selectById(userId);
        // 判断用户是否选择余额进行支付
        if (null != reqOrderCart.getBalance() && reqOrderCart.getBalance() == 1) {
            // 这里去减少用户的余额信息，然后更新用户支付订单信息，显示当前用户需要有多少支付多少钱，如果用户不需要额外支付则用户支付成功
            BigDecimal usermoney = jslUserMapper.selectMoneyByUserId(userId);
            //用户余额大于实付款金额
            if (usermoney.compareTo(totalAmount) == 1) {
                jslOrder.setDeduction(totalAmount);
                BigDecimal userMoney = usermoney.subtract(totalAmount);
                totalAmount = new BigDecimal("0.00");
                jslOrder.setTotalAmount(totalAmount);
                jslUserMapper.updateUserMoneyById(userMoney, userId);
            }
            //用户余额小于实付款金额
            else if (usermoney.compareTo(totalAmount) == -1) {
                jslOrder.setDeduction(usermoney);
                totalAmount = totalAmount.subtract(usermoney);
                BigDecimal userMoney = new BigDecimal("0.00");
                jslUserMapper.updateUserMoneyById(userMoney, userId);
                jslOrder.setTotalAmount(totalAmount);
            }
            //用户金额等于实付款金额
            else if (usermoney.compareTo(totalAmount) == 0) {
                jslOrder.setDeduction(usermoney);
//                BigDecimal userMoney = jslOrder.getTotalAmount().subtract(usermoney);
                totalAmount = new BigDecimal("0.00");
                jslUserMapper.updateUserMoneyById(totalAmount, userId);
                jslOrder.setTotalAmount(totalAmount);
            }
        }
        totalAmount = totalAmount.setScale(2,BigDecimal.ROUND_HALF_UP);
        if(reqOrderCart.getId()!=null) jslOrder.setFareTitle(reqOrderCart.getId().toString());
        // 计算实际需要支付多少钱 根据用户选择计算 减去用户的余额信息
        // 当前商品选择银行承兑
        if (null != reqOrderCart.getBank() && reqOrderCart.getBank() == 1) {
//            jslOrder.setOrderType(2);
            JslConfig jslConfig = jslConfigMapper.selectOne(null);
            if (null != jslConfig) {
                BigDecimal tax = jslConfig.getTax();
                jslOrder.setOrderRate(tax);
                String per = "0.01";
                BigDecimal decimal = new BigDecimal(per).multiply(tax);
                BigDecimal multiply = totalAmount.multiply(decimal).setScale(2,BigDecimal.ROUND_HALF_UP);
                totalAmount = totalAmount.add(multiply);
                jslOrder.setTotalAmount(totalAmount);
                jslOrder.setOrderType(7);
                jslOrder.setOrderTax(multiply);
            }
        } else if (null != reqOrderCart.getBank() && reqOrderCart.getBank() == 0 && reqOrderCart.getPayment()==0) {
            //微信支付
            BigDecimal result = jslCommissionService.selectJslpoundage();
            jslOrder.setOrderRate(result);
            BigDecimal multiply = totalAmount.multiply(result).setScale(2,BigDecimal.ROUND_HALF_UP);
            totalAmount = totalAmount.add(multiply);
            jslOrder.setTotalAmount(totalAmount);
            jslOrder.setOrderType(5);
            jslOrder.setOrderTax(multiply);
        }else if(null != reqOrderCart.getBank() && reqOrderCart.getBank() == 0 && reqOrderCart.getPayment()==1){
            //支付宝支付
            BigDecimal result = jslCommissionService.selectJslpoundage();
            jslOrder.setOrderRate(result);
            BigDecimal multiply = totalAmount.multiply(result).setScale(2,BigDecimal.ROUND_HALF_UP);
            totalAmount = totalAmount.add(multiply);
            jslOrder.setTotalAmount(totalAmount);
            jslOrder.setOrderType(6);
            jslOrder.setOrderTax(multiply);
        }
        else if(null != reqOrderCart.getBank() && reqOrderCart.getBank() ==2){
            jslOrder.setOrderType(2);
            jslOrder.setOrderRate(new BigDecimal("0.00"));
            jslOrder.setTotalAmount(totalAmount);
        }
        /*
        银行转账
         */
        /*if (reqOrderCart.getTransfer() == 0) {
            jslOrder.setOrderType(2);
        }*/
        jslOrderGoodsList.forEach(jslOrderGoods -> {
            jslOrderGoods.setOrderId(jslOrder.getOrderId());
            jslOrderGoodsMapper.insert(jslOrderGoods);
        });

        //支付金额为0 让用户支付0.01
        if (totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP).compareTo(new BigDecimal("0.00")) == 0) {
            jslOrderArrears.setArrearsAmount(new BigDecimal("0.01"));
        } else {
            //支付功能的支付金额
            jslOrderArrears.setArrearsAmount(totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP));
        }

        jslOrderMapper.insert(jslOrder);
        jslOrderArrears.setOrderId(jslOrder.getOrderId());
        jslOrderArrearsMapper.insert(jslOrderArrears);
        // 删除购物车信息
        jslCartMapper.deleteBatchIds(cartList.stream().map(JslCart::getId).collect(Collectors.toList()));


        // 是否需要开票
        if (reqOrderCart.getFare() == 1) {
            JslUserExtend jslUserExtend = jslUserExtendMapper.selectJslUserExtendById(reqOrderCart.getId());
            if (jslUserExtend == null) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "请前往我的-发票申请录入抬头信息");
            }
            // 根据当前用户判断是否为个人用户信息
           /* jslOrder.setFareTitle(
                    jslUserExtend.getFareType() == 1 ? jslUserExtend.getRealName() : jslUserExtend.getInvoiceTitle());
            //向用户已申请发票表插入信息 'jsl_user_fare_applied'
            JslUserFareApplied jslUserFareApplied = new JslUserFareApplied();
            jslUserFareApplied.setUserId(userId);
            jslUserFareApplied.setExtendId(jslUserExtend.getId());
            //应支付金额
            jslUserFareApplied.setFareMoney(totalAmount);
            if (jslUserExtend.getFareType() == 1) jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setAddress(jslUserExtend.getAddress());
            jslUserFareApplied.setEmail(jslUserExtend.getEmail());
            jslUserFareApplied.setBank(jslUserExtend.getBank());
            jslUserFareApplied.setBankAccount(jslUserExtend.getBankAccount());
            jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setInvoiceTitle(jslUserExtend.getInvoiceTitle());
            jslUserFareApplied.setRealName(jslUserExtend.getRealName());
            jslUserFareApplied.setPhone(jslUserExtend.getPhone());
            jslUserFareApplied.setTaxpayer(jslUserExtend.getTaxpayer());
            jslUserFareApplied.setFareType(jslUserExtend.getFareType());

            jslUserFareAppliedMapper.insert(jslUserFareApplied);*/
            //向用户申请发票订单表插入数据 'jsl_user_fare_order_apply'
            JslUserFareOrderApply jslUserFareOrderApply = new JslUserFareOrderApply();
            //判断是否是多个订单,多个订单不向数据库存入orderId
            if (jslOrder.getOrderId().contains(",")) {
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalAmount);
                jslUserFareOrderApply.setFareId(reqOrderCart.getId());
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
                jslUserFareOrderApply.setFareId(jslUserExtend.getId());
//                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            } else {
                // 配置接收发票的邮箱
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalAmount);
                jslUserFareOrderApply.setFareId(reqOrderCart.getId());
                jslUserFareOrderApply.setOrderId(jslOrder.getOrderId());
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
//                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            }
            jslUserFareOrderApplyMapper.insert(jslUserFareOrderApply);
        }

        return jslOrder.getOrderId();
    }


    /**
     * saveUserQuicklyOrderByUserId: 用户选择立即下单的操作<br/>
     *
     * @param reqOrderQuickly
     * @param userId
     * @return
     * @author Kai.Wang
     * @date 2021/11/22 13:55
     */
    @Override
    @Transactional
    public Object saveUserQuicklyOrderByUserId(ReqOrderQuickly reqOrderQuickly, Long userId) {
        BigDecimal totalamount = new BigDecimal("0.00");

        // 创建订单对象
        JslOrder jslOrder = new JslOrder();
        // 下单人
        jslOrder.setUserId(userId);
        // 订单状态;0：未完结 1：已完结
//        int ordinal = OrderStatus.TO_BE_PAID.ordinal();
        jslOrder.setOrderStatus(0);
        // 订单代发货
        jslOrder.setLogisticStatus(0);
        // 支付状态;0：未支付 1：支付完成 2：已支付预付款
        jslOrder.setPayStatus(0);
        // 下单时间
        jslOrder.setAddTime(LocalDateTime.now());
        // 是否分成
        jslOrder.setIsDistribute(0);
        // 用户订单备注
        jslOrder.setUserNote(reqOrderQuickly.getUserNote());

        JslUserCouponVo jslUserCouponVo = null;
        // 查询当前是否有优惠券信息
        if (null != reqOrderQuickly.getCouponId() && reqOrderQuickly.getCouponId() != 0) {
            //如果查询的list为0 提示没有对应的优惠价
            List<JslUserCouponVo> jslUserCouponVos = jslUserCouponMapper.selectJslUserCouponVoListBytow(reqOrderQuickly.getCId(), userId);
            if (jslUserCouponVos.size() == 0) {
                throw new JiuLuException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前选择优惠券不存在或已过期");
            } else {
                jslUserCouponVo = jslUserCouponVos.get(0);
            }


        }
        // 查询当前商品信息
        GoodsVo goodsVo = jslGoodsMapper.selectGoodsVoByGoodsId(reqOrderQuickly.getGoodsId());
        if (null == goodsVo || !goodsVo.getGoodsStatus().equals(1)) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前提交订单商品不存在或已下架");
        }
        // 查询当前商品的规格信息
        // 查询当前商品规格信息
        GoodsAttrVo goodsAttrVo = jslGoodsAttrMapper.selectGoodsAttrVoByGoodsAttrId(reqOrderQuickly.getAttrId());
        if (null == goodsAttrVo) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前提交订单商品不存在或已下架");
        }
        // 检查当前规格的库存信息
        if (goodsAttrVo.getStoreCount() - reqOrderQuickly.getNums() < 0) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前商品库存不足，请重新选择");
        }

        // 查询当前用户提交的地址信息
        JslUserAddress jslUserAddress =
                jslUserAddressMapper.selectJslUserAddressByUserIdWithAddressId(userId, reqOrderQuickly.getAddressId());
        if (null == jslUserAddress) {
            throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前选择的地址不存在，请重新提交");
        }
        jslOrder.setConsignee(jslUserAddress.getName());
        jslOrder.setCountry(0);
        jslOrder.setProvinceId(jslUserAddress.getProvinceId());
        jslOrder.setProvinceName(jslUserAddress.getProvinceName());
        jslOrder.setCityId(jslUserAddress.getCityId());
        jslOrder.setCityName(jslUserAddress.getCityName());
        jslOrder.setDistrictId(jslUserAddress.getDistrictId());
        jslOrder.setDistrictName(jslUserAddress.getDistrictName());
        jslOrder.setAddress(jslUserAddress.getAddress());
        jslOrder.setPhone(jslUserAddress.getPhone());

        // 当前产品的邮费金额
        jslOrder.setLogisticPrice(BigDecimal.ZERO);
        if (goodsVo.getFreeShipping() != 1) {
            // 查询出当前商品配置的运费信息
            JslLogisticAreaVo jslLogisticAreaVo =
                    jslLogisticAreaMapper.selectJslLogisticAreaVoByLogisticIdWithAreaId(goodsVo.getLogisticId(),
                            jslUserAddress.getProvinceId());
            if (null == jslLogisticAreaVo) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前商品不属于配送区域，请联系客服解决");
            }
            // 物流的信息
//            jslOrder.setLogisticName(jslLogisticAreaVo.getCompanyName());
//            jslOrder.setLogisticCode(jslLogisticAreaVo.getCompanyCode());
            // 计算当前产品的运费信息，计算当前的重量向上取整

            //截取weightprice字符串,拿到金额
            BigDecimal weight = reqOrderQuickly.getWeight();
            String weightprice = jslLogisticAreaVo.getWeightprice();
            //   String weightprice=wp.replace("\\","").replace("[","").replace("]","");
            JSONArray object = JSON.parseArray(weightprice);
            List<JslArea> list = JSONObject.parseArray(object.toJSONString(), JslArea.class);
            for (JslArea s : list) {
                BigDecimal maxWeight = s.getMaxWeight();
                BigDecimal mixWeight = s.getMixWeight();
                BigDecimal money = s.getMoney();
                if (mixWeight.compareTo(weight) == -1 && maxWeight.compareTo(weight) == 1) {
                    BigDecimal f = weight.multiply(money);
                    jslOrder.setLogisticPrice(f);
                } else if (maxWeight.compareTo(weight) == 0) {
                    BigDecimal f = weight.multiply(money);
                    jslOrder.setLogisticPrice(f);
                } else if (mixWeight.compareTo(weight) == 0) {
                    BigDecimal f = weight.multiply(money);
                    jslOrder.setLogisticPrice(f);
                }
            }
        } else {
            jslOrder.setLogisticPrice(new BigDecimal("0.00"));
        }
        // 订单商品信息
        // 订单中的商品信息
        JslOrderGoods jslOrderGoods = new JslOrderGoods();
        // 商品Id
        jslOrderGoods.setGoodsId(goodsVo.getGoodsId());
        // 商品名称
        jslOrderGoods.setGoodsName(goodsVo.getGoodsName());
        // 商品规格Id
        jslOrderGoods.setGoodsAttrId(goodsAttrVo.getAttrId());
        // 商品规格名称
        jslOrderGoods.setGoodsAttrName(goodsAttrVo.getAttrName());
        // 商品购买数量
        jslOrderGoods.setGoodsNum(reqOrderQuickly.getNums());
        //商品图片
        jslOrderGoods.setGoodsAttrImage(goodsVo.getGoodsImages());
        // 计算出当前商品的总重量信息
        BigDecimal goodsWeight = goodsAttrVo.getAttrWeight().multiply(BigDecimal.valueOf(reqOrderQuickly.getNums()));
        //判断是否包邮，修改邮费为0
        if (goodsVo.getFreeShipping() == 1) {
            jslOrder.setLogisticPrice(new BigDecimal("0.00"));
        }
        // 全款订单
        jslOrder.setOrderId(String.format("QK%s", RandomUtils.getOrderNo()));
        // 配置当前商品全额购买的金额信息
        if (goodsAttrVo.getSalePricesList().size() > 0) {//有
            jslOrderGoods.setGoodsPrice(getGoodsCurrentPrice(goodsAttrVo.getSalePricesList(), goodsWeight));
        } else {
            jslOrderGoods.setGoodsPrice(goodsAttrVo.getAttrPrice());
        }
        int i = goodsAttrVo.getStoreCount() - jslOrderGoods.getGoodsNum();
        goodsAttrVo.setStoreCount(i);
        jslOrder.setOrderType(0);
        // 设置商品的总价 商品规格单价 * 商品数量
        totalamount = jslOrderGoods.getGoodsPrice().multiply(goodsWeight).setScale(2, RoundingMode.HALF_UP);
        jslOrder.setGoodsPrice(totalamount);
        // 订单号
        jslOrderGoods.setOrderId(jslOrder.getOrderId());

        //计算当前需要付款的金额，并设置保留两位小数
        // 当前订单的总金额 商品金额 + 邮费金额
        if (jslOrder.getLogisticPrice().compareTo(new BigDecimal("0.00")) == 1) {
            totalamount = totalamount.add(jslOrder.getLogisticPrice()).setScale(2, RoundingMode.HALF_UP);
            jslOrder.setTotalAmount(totalamount);
        }else {
            jslOrder.setTotalAmount(totalamount.add(jslOrder.getLogisticPrice()));
        }

        /**
         * 计算优惠券抵扣金额，当前优惠券的使用条件为支付金额需要大于等于优惠券使用条件
         */
        if (null != jslUserCouponVo && -1 != totalamount.compareTo(jslUserCouponVo.getAmount())) {
            if (jslUserCouponVo.getCategory() == 1) {
//                JslCoupon jslCoupon = jslCouponMapper.selectById(reqOrderQuickly.getCouponId());
                BigDecimal remAmount = jslUserCouponVo.getRemAmount();
//                BigDecimal scale = jslUserCouponVo.getDiscount().multiply(new BigDecimal("0.01"));
//                BigDecimal discount = totalamount.multiply(scale);
//                jslUserCouponVo.setDiscount(discount);
                //判断代金券是否有余额
//                if (remAmount1.compareTo(new BigDecimal("0.00")) != 0) {
//                    //如果订单金额比代金券余额大
//                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
//                    jslOrder.setCouponPrice(remAmount1);
//                    jslUserCouponVo.setStatus(1);
//                } else {
//                    //代金券余额为空时
//                    BigDecimal remAmount = amount.subtract(discount);
//                    jslUserCouponVo.setRemAmount(remAmount);
//                    if (remAmount.compareTo(new BigDecimal("0.00")) <= 0) {
//                        jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
//                        jslUserCouponVo.setStatus(1);
//                    }
//                    jslOrder.setCouponPrice(discount);
//                }
                //订单金额比代金券余额大
                if(totalamount.compareTo(remAmount) > 0){
//                    totalamount = totalamount.subtract(remAmount);
                    jslOrder.setCouponPrice(remAmount);
                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                    jslUserCouponVo.setStatus(1);
                } else if(totalamount.compareTo(remAmount) == 0){
//                    totalamount =new BigDecimal("0.00");
                    jslOrder.setCouponPrice(remAmount);
                    jslUserCouponVo.setRemAmount(new BigDecimal("0.00"));
                    jslUserCouponVo.setStatus(1);
                } else if(totalamount.compareTo(remAmount) < 0){
                    jslOrder.setCouponPrice(totalamount);
                    jslUserCouponVo.setStatus(3);
//                    totalamount = new BigDecimal("0.00");
                    jslUserCouponVo.setRemAmount(remAmount.subtract(totalamount));
                }

            }
            jslUserCouponVo.setOrderId(jslOrder.getOrderId());
            jslUserCouponVo.setUseTime(LocalDateTime.now());
            jslUserCouponVo.setUpdateTime(LocalDateTime.now());
            JslCouponUseList couponUse=new JslCouponUseList();
            if (jslUserCouponVo.getCategory() == 0) {
                jslUserCouponVo.setStatus(1);
                jslOrder.setCouponPrice(jslUserCouponVo.getDiscount());
                couponUse.setOrderId(jslOrder.getOrderId());
                couponUse.setUserId(userId);
                couponUse.setCouponId(jslUserCouponVo.getCouponId());
                couponUse.setUserCouponId(jslUserCouponVo.getId());
                jslCouponUseMapper.insert(couponUse);
            }
            if(jslUserCouponVo.getRemAmount().compareTo(new BigDecimal("0.00"))>=0  && jslUserCouponVo.getCategory()==1){
                couponUse.setOrderId(jslOrder.getOrderId());
                couponUse.setUserId(userId);
                couponUse.setCouponId(jslUserCouponVo.getCouponId());
                couponUse.setUserCouponId(jslUserCouponVo.getId());
                jslCouponUseMapper.insert(couponUse);
            }
                jslUserCouponMapper.updateUserCouponVo(jslUserCouponVo);

            //减去优惠价的价格
            totalamount = totalamount.subtract(jslOrder.getCouponPrice());
            jslOrder.setTotalAmount(totalamount);
//            jslOrder.setTotalAmount(
//                    jslOrder.getGoodsPrice());
            //    jslUserCouponMapper.updateById(jslUserCouponVo);
        } else {
            jslOrder.setCouponPrice(BigDecimal.ZERO);
        }


//        // 计算当前需要付款的金额，并设置保留两位小数
//        // 当前订单的总金额 商品金额 - 优惠券金额 + 邮费金额

        //应付金额减去优惠价金额
        jslOrder.setOrderAmount(totalamount);

/**
 * wj----修改了发票抬头有多个此逻辑不通注掉
 */


        JslUser jslUser = jslUserMapper.selectById(userId);
        // 判断用户是否选择余额进行支付
        if (null != reqOrderQuickly.getBalance() && reqOrderQuickly.getBalance() == 1) {
            // 这里去减少用户的余额信息，然后更新用户支付订单信息，显示当前用户需要有多少支付多少钱，如果用户不需要额外支付则用户支付成功
            BigDecimal usermoney = jslUserMapper.selectMoneyByUserId(userId);
            if (usermoney.compareTo(totalamount) == 1) {
                jslOrder.setDeduction(totalamount);
                BigDecimal userMoney = usermoney.subtract(totalamount);
                totalamount = new BigDecimal("0.00");
                jslOrder.setTotalAmount(totalamount);
                jslUserMapper.updateUserMoneyById(userMoney, userId);
            } else if (usermoney.compareTo(totalamount) == -1) {
                jslOrder.setDeduction(usermoney);
                totalamount = totalamount.subtract(usermoney);
                BigDecimal userMoney = new BigDecimal("0.00");
                jslUserMapper.updateUserMoneyById(userMoney, userId);
                jslOrder.setTotalAmount(totalamount);
            } else if (usermoney.compareTo(totalamount) == 0) {
                jslOrder.setDeduction(usermoney);
//                BigDecimal userMoney = jslOrder.getTotalAmount().subtract(usermoney);
                totalamount = new BigDecimal("0.00");
                jslUserMapper.updateUserMoneyById(totalamount, userId);
                jslOrder.setTotalAmount(totalamount);
            }
        }

        if(reqOrderQuickly.getId()!=null) jslOrder.setFareTitle(reqOrderQuickly.getId().toString());
        // 创建订单付款信息
        JslOrderArrears jslOrderArrears = new JslOrderArrears();
        jslOrderArrears.setArrearsId(String.format("%s%d", jslOrder.getOrderId(), 1));
        jslOrderArrears.setOrderId(jslOrder.getOrderId());
        jslOrderArrears.setArrearsPercent(jslOrder.getOrderPercent());

        jslOrderArrears.setPayStatus(0);
        jslOrderArrears.setCreateTime(LocalDateTime.now());
        totalamount=totalamount.setScale(2,BigDecimal.ROUND_HALF_UP);
        // 计算实际需要支付多少钱 根据用户选择计算 减去用户的余额信息
        // 当前商品选择银行承兑
        if (null != reqOrderQuickly.getBank() && reqOrderQuickly.getBank() == 1) {
//            jslOrder.setOrderType(2);
            JslConfig jslConfig = jslConfigMapper.selectOne(null);

            if (null != jslConfig) {
                BigDecimal tax = jslConfig.getTax();
                jslOrder.setOrderRate(tax);
                String per = "0.01";
                BigDecimal decimal = new BigDecimal(per).multiply(tax);
                BigDecimal multiply = totalamount.multiply(decimal).setScale(2,BigDecimal.ROUND_HALF_UP);
                totalamount = totalamount.add(multiply);
                jslOrder.setTotalAmount(totalamount);
                jslOrder.setOrderTax(multiply);
                jslOrder.setOrderType(7);
            }
        } else if (reqOrderQuickly.getBank()!=null && reqOrderQuickly.getBank() == 0 && reqOrderQuickly.getPayment() ==0) {
            //微信支付
            BigDecimal result = jslCommissionService.selectJslpoundage();
//            result =result.multiply(new BigDecimal("100"));
            jslOrder.setOrderRate(result);
            BigDecimal multiply = totalamount.multiply(result).setScale(2,BigDecimal.ROUND_HALF_UP);
            totalamount = totalamount.add(multiply);
            jslOrder.setTotalAmount(totalamount);
            jslOrder.setOrderType(5);
            jslOrder.setOrderTax(multiply);
        } else if (reqOrderQuickly.getBank()!=null && reqOrderQuickly.getBank() == 0 && reqOrderQuickly.getPayment() ==1) {
            //支付宝支付
            BigDecimal result = jslCommissionService.selectJslpoundage();
            jslOrder.setOrderRate(result);
            BigDecimal multiply = totalamount.multiply(result).setScale(2,BigDecimal.ROUND_HALF_UP);
            totalamount = totalamount.add(multiply);
            jslOrder.setTotalAmount(totalamount);
            jslOrder.setOrderType(6);
            jslOrder.setOrderTax(multiply);
        } else if(reqOrderQuickly.getBank() !=null && reqOrderQuickly.getBank()==2){
            //银行转账
            jslOrder.setOrderType(2);
            jslOrder.setTotalAmount(totalamount);
        }

        /*if (reqOrderQuickly.getTransfer() == 0) {
            jslOrder.setOrderType(2);
        }*/
        if (totalamount.setScale(2, BigDecimal.ROUND_HALF_UP).compareTo(new BigDecimal("0.00")) == 0) {
            jslOrderArrears.setArrearsAmount(new BigDecimal("0.01"));
        } else {
            jslOrderArrears.setArrearsAmount(totalamount.setScale(2, BigDecimal.ROUND_HALF_UP));
        }
        jslOrderMapper.insert(jslOrder);
        jslOrderArrearsMapper.insert(jslOrderArrears);
        jslOrderGoodsMapper.insert(jslOrderGoods);
        jslGoodsAttrMapper.updateById(goodsAttrVo);


        // 是否需要开票
        if (reqOrderQuickly.getFare() == 1) {
            JslUserExtend jslUserExtend = jslUserExtendMapper.selectJslUserExtendById(reqOrderQuickly.getId());

            if (jslUserExtend == null) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "请前往我的-发票申请录入抬头信息");
            }
            // 根据当前用户判断是否为个人用户信息
           /* jslOrder.setFareTitle(
                    jslUserExtend.getFareType() == 1 ? jslUserExtend.getRealName() : jslUserExtend.getInvoiceTitle());
            //向用户已申请发票表插入信息 'jsl_user_fare_applied'
            JslUserFareApplied jslUserFareApplied = new JslUserFareApplied();
            jslUserFareApplied.setUserId(userId);
            jslUserFareApplied.setExtendId(jslUserExtend.getId());
            jslUserFareApplied.setFareMoney(totalamount);
            if (jslUserExtend.getFareType() == 1) jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setAddress(jslUserExtend.getAddress());
            jslUserFareApplied.setEmail(jslUserExtend.getEmail());
            jslUserFareApplied.setBank(jslUserExtend.getBank());
            jslUserFareApplied.setBankAccount(jslUserExtend.getBankAccount());
            jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setInvoiceTitle(jslUserExtend.getInvoiceTitle());
            jslUserFareApplied.setRealName(jslUserExtend.getRealName());
            jslUserFareApplied.setPhone(jslUserExtend.getPhone());
            jslUserFareApplied.setTaxpayer(jslUserExtend.getTaxpayer());
            jslUserFareApplied.setFareType(jslUserExtend.getFareType());
            jslUserFareApplied.setCreateTime(LocalDateTime.now());
            jslUserFareAppliedMapper.insert(jslUserFareApplied);
            */

            //向用户申请发票订单表插入数据 'jsl_user_fare_order_apply'
            JslUserFareOrderApply jslUserFareOrderApply = new JslUserFareOrderApply();
            //判断是否是多个订单,多个订单不向数据库存入orderId
            if (jslOrder.getOrderId().contains(",")) {
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalamount);
                jslUserFareOrderApply.setFareId(reqOrderQuickly.getId());
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
                jslUserFareOrderApply.setFareId(jslUserExtend.getId());
//                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            } else {
                // 配置接收发票的邮箱
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalamount);
                jslUserFareOrderApply.setFareId(reqOrderQuickly.getId());
                jslUserFareOrderApply.setOrderId(jslOrder.getOrderId());
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
//                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            }
            jslUserFareOrderApplyMapper.insert(jslUserFareOrderApply);
        }

        // 创建支付订单信息
        return jslOrder.getOrderId();
    }

    /**
     * selectJslOrderVoByUserId: 查询当前的订单信息<br/>
     *
     * @param currentPage
     * @param pageSize
     * @param currentDate
     * @param userId
     * @return
     * @author Kai.Wang
     * @date 2021/11/24 15:31
     */
    @Override
    public PageInfo<?> selectJslOrderVoByUserId(Integer currentPage, Integer pageSize, LocalDateTime currentDate,
                                                Long userId, int orderTotalStatus) {
        PageHelper.startPage(currentPage, pageSize);
        List<JslOrderVo> list = jslOrderMapper.selectJslOrderVoByUserId(currentDate, userId, orderTotalStatus);
        return new PageInfo<>(list);
    }

    /**
     * selectJslOrderVoByUserId: 查询当前没开票的订单信息<br/>
     *
     * @param currentPage
     * @param pageSize
     * @param currentDate
     * @param userId
     * @return
     * @author Kai.Wang
     * @date 2021/11/24 15:31
     */
    @Override
    public PageInfo<?> selectFareJslOrderVoByUserId(Integer currentPage, Integer pageSize, LocalDateTime currentDate,
                                                    Long userId, int orderTotalStatus) {
//        PageHelper.startPage(currentPage, pageSize);
        List<JslOrderVo> list = jslOrderMapper.selectFareJslOrderVoByUserId(currentDate, userId, orderTotalStatus);
        return new PageInfo<>(list);
    }

    /**
     * selectJslOrderArrearsVoByUserId: 查询用户的预定订单信息<br/>
     *
     * @param currentPage
     * @param pageSize
     * @param currentDate
     * @param userId
     * @return
     * @author Kai.Wang
     * @date 2021/11/24 16:52
     */
    @Override
    public PageInfo<?> selectJslOrderArrearsVoByUserId(Integer currentPage, Integer pageSize, LocalDateTime currentDate,
                                                       Long userId, int orderTotalStatus) {
        PageHelper.startPage(currentPage, pageSize);
        List<JslOrderArrearsVo> list = jslOrderMapper.selectJslOrderArrearsVoByUserId(currentDate, userId, orderTotalStatus);
        return new PageInfo<>(list);
    }

    @Override
    public List<JslOrderVo> selectJslOrderByUserId(Long userId, LocalDateTime addTime, Integer orderTotalStatus) {
        return jslOrderMapper.selectJslOrderByUserId(userId, addTime, orderTotalStatus);
    }

    @Override
    public List<JslOrderVo> selectTotalOrderByUserId(Long userId, LocalDateTime addTime, Integer orderTotalStatus) {
        return jslOrderMapper.selectTotalOrderByUserId(userId, addTime, orderTotalStatus);
    }


    @Override
    public List<JslOrderVo> selectBankOrderByUserId(Long userId, LocalDateTime addTime, Integer orderTotalStatus) {
        return jslOrderMapper.selectBankOrderByUserId(userId, addTime, orderTotalStatus);
    }

    /**
     * selectJslOrderVoByUserIdForBank: 获取银行承兑的订单信息<br/>
     *
     * @param currentPage
     * @param pageSize
     * @param currentDate
     * @param userId
     * @return
     * @author Kai.Wang
     * @date 2021/11/24 16:51
     */
    @Override
    public PageInfo<?> selectJslOrderVoByUserIdForBank(Integer currentPage, Integer pageSize, LocalDateTime currentDate,
                                                       Long userId) {
        PageHelper.startPage(currentPage, pageSize);
        List<JslOrderVo> list = jslOrderMapper.selectJslOrderVoByUserIdForBank(currentDate, userId);
        return new PageInfo<>(list);
    }

    /**
     * selectJslOrderVoByUserIdAndOrderId: 根据当前用户的Id和订单Id查询订单详细信息<br/>
     *
     * @param orderId
     * @param userId
     * @return
     * @author Jason.Wang
     * @date 2021/12/26 11:56
     */
    @Override
    public JslOrderVo selectJslOrderVoByUserIdAndOrderId(String orderId, Long userId) {
        return jslOrderMapper.selectJslOrderVoByUserIdAndOrderId(orderId, userId);
    }

    /**
     * selectJslOrderVoByOrderId: 通过当前订单Id查询订单信息<br/>
     *
     * @param orderId
     * @return
     * @author Jason.Wang
     * @date 2021/12/29 0:40
     */
    @Override
    public JslOrderVo selectJslOrderVoByOrderId(String orderId) {
        return jslOrderMapper.selectJslOrderVoByOrderId(orderId);
    }

    /**
     * updateOrderPayMentInfo: 更新当前订单的付款状态信息<br/>
     *
     * @param orderId
     * @param paySuccessDate
     * @param bankTrxId
     * @return
     * @author Jason.Wang
     * @date 2022/1/1 11:09
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateOrderPayMentInfo(String orderId, LocalDateTime paySuccessDate, String bankTrxId) throws InterruptedException {
        JslOrderArrears jslOrderArrears = jslOrderArrearsMapper.selectById(orderId);
        if (null != jslOrderArrears) {
            // 根据当前订单付款信息，获取主订单信息
            JslOrderVo jslOrderVo = jslOrderMapper.selectJslOrderVoByOrderId(jslOrderArrears.getOrderId());
            if (null == jslOrderVo) {
                return false;
            }
            jslOrderArrears.setPayStatus(1);
            jslOrderArrears.setTransactionId(bankTrxId);
            jslOrderArrearsMapper.updateById(jslOrderArrears);
            // 全款订单
            if (jslOrderArrears.getArrearsPercent() == 100 && jslOrderVo.getOrderType() == 0) {
                jslOrderVo.setTransactionId(bankTrxId);
                jslOrderVo.setPayTime(paySuccessDate);
                jslOrderVo.setPayStatus(1);
                jslOrderMapper.updateById(jslOrderVo);
                // 更新分润信息
                jslUserService.calculateProfit(orderId, jslOrderVo.getUserId(), jslOrderVo.getTotalAmount());
            } else if (jslOrderVo.getOrderType() == 1) {
                // 预付款订单类型
                if (jslOrderVo.getPayStatus() == 0) {
                    jslOrderVo.setPayStatus(2);
                    jslOrderVo.setTransactionId(bankTrxId);
                    jslOrderVo.setPayTime(paySuccessDate);
                    jslOrderMapper.updateById(jslOrderVo);
                }
                if (jslOrderVo.getPayStatus() == 2) {
                    jslOrderVo.setTransactionId(bankTrxId);
                    jslOrderVo.setPayTime(paySuccessDate);
                    jslOrderVo.setPayStatus(1);
                    jslOrderMapper.updateById(jslOrderVo);
                }
            }
//            if (jslOrderVo.getPayStatus() == 1||jslOrderVo.getPayStatus() == 2) {
            //修改订单为支付成功
            JslOrder jslOrder = jslOrderMapper.selectById(orderId.substring(0, orderId.length() - 1));
            if (jslOrder.getFrequency()<3){
                jslOrder.setPayStatus(1);
                LocalDateTime now = LocalDateTime.now();
                Thread.sleep(10000);
                jslOrder.setPayTime(now);

                Integer frequency = jslOrder.getFrequency();
                frequency=frequency==null?1:frequency+1;
                jslOrder.setFrequency(frequency);

                jslOrderMapper.updateById(jslOrder);
            }

            // 更新分润信息
//                jslUserService.calculateProfit(orderId, jslOrderVo.getUserId(), jslOrderVo.getTotalAmount());
            return true;
//            }

        }
        return false;
    }

    /**
     * updateCancelOrderByOrderIdAndUserId: 取消当前订单信息<br/>
     *
     * @param reqCancelOrder
     * @param jslOrderVo
     * @return
     * @author Jason.Wang
     * @date 2022/1/1 22:49
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateCancelOrderByOrderIdAndUserId(ReqCancelOrder reqCancelOrder, JslOrderVo jslOrderVo) {
        JslOrderVo currentJslOrderVo =
                jslOrderMapper.selectJslOrderVoByUserIdAndOrderId(jslOrderVo.getOrderId(), jslOrderVo.getUserId());
        if (null == jslOrderVo || jslOrderVo.getOrderStatus() != 0) {
            throw new JiuLuException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前订单不能申请退货退款");
        }
        JslLogisticCompany jslLogisticCompany = jslLogisticCompanyMapper.selectById(reqCancelOrder.getCompanyId());
        if (null == jslLogisticCompany) {
            throw new JiuLuException(ConstantCode.PARAM_EXCEPTION.getCode(), "选择的快递公司不存在");
        }
        QueryWrapper<JslOrder> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.eq("order_id", jslOrderVo.getOrderId());
        orderQueryWrapper.eq("user_id", jslOrderVo.getUserId());
        orderQueryWrapper.eq("order_status", 1);
        orderQueryWrapper.eq("pay_status", 1);
        // 当前订单的取消状态为审核通过，当后台审核通过之后状态会变更成2，审核不通过编程3
        orderQueryWrapper.eq("cancel_status", 2);
        orderQueryWrapper.eq("cancel_type", 2);
        currentJslOrderVo.setCancelTime(LocalDateTime.now());
        // 更新当前退款状态为待打款
        currentJslOrderVo.setCancelStatus(4);
        jslOrderMapper.update(currentJslOrderVo, orderQueryWrapper);
        return true;
    }

    /**
     * updateCancelOrderByOrderIdAndUserIdForApply: 申请退货退款<br/>
     *
     * @param jslOrderVo
     * @return
     * @author Jason.Wang
     * @date 2022/1/2 9:52
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateCancelOrderByOrderIdAndUserIdForApply(JslOrderVo jslOrderVo) {
        JslOrderVo currentJslOrderVo =
                jslOrderMapper.selectJslOrderVoByUserIdAndOrderId(jslOrderVo.getOrderId(), jslOrderVo.getUserId());
        if (null != jslOrderVo || jslOrderVo.getOrderStatus() != 0) {
            QueryWrapper<JslOrder> orderQueryWrapper = new QueryWrapper<>();
            orderQueryWrapper.eq("order_id", jslOrderVo.getOrderId());
            orderQueryWrapper.eq("user_id", jslOrderVo.getUserId());
            orderQueryWrapper.eq("order_status", 1);
            orderQueryWrapper.eq("pay_status", 1);
            currentJslOrderVo.setCancelTime(LocalDateTime.now());
            // 配置取消类型为退货
            currentJslOrderVo.setCancelType(2);
            // 状态为申请退货
            currentJslOrderVo.setCancelStatus(0);
            jslOrderMapper.update(currentJslOrderVo, orderQueryWrapper);
        } else {
            throw new JiuLuException(ConstantCode.PARAM_EXCEPTION.getCode(), "当前订单不能申请退货退款");
        }

        return true;
    }

    /**
     * 订单确认收货
     *
     * @param reqOrderConfirmReceipt
     */
    @Override
    public void orderConfirmReceipt(ReqOrderConfirmReceipt reqOrderConfirmReceipt) {
        jslOrderMapper.orderConfirmReceipt(reqOrderConfirmReceipt);

    }

    @Resource
    IJslShareProfitRecordService jslShareProfitRecordService;

    @Override
    public PageInfo<UserOrderPageVo> getUserOrderPage(int page, int size, Long userId,Long inviteId) {
        //增加 如果后台对用户改变代理人 只显示当前代理人下产生的订单
        QueryWrapper<JslShareProfitRecord> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(JslShareProfitRecord::getUserId,inviteId);
        List<String> orderIds = jslShareProfitRecordService.list(wrapper).stream().map(JslShareProfitRecord::getOrderId).collect(Collectors.toList());

        List<UserOrderPageVo> userOrderPage = jslOrderMapper.getUserOrderPage(userId);
        PageHelper.startPage(page, size);

        int total = userOrderPage.size();

        userOrderPage = userOrderPage.stream().filter(e -> orderIds.contains(e.getOrderId())).collect(Collectors.toList());
        userOrderPage = userOrderPage.stream().skip((page - 1) * size).limit(size).collect(Collectors.toList());

        PageInfo<UserOrderPageVo> pageInfo = new PageInfo<>(userOrderPage);
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(size);
        pageInfo.setTotal(total);
        pageInfo.setList(userOrderPage);

        return pageInfo;
    }

    @Override
    public BigDecimal getJslTax() {
        return jslConfigMapper.selectOne(null).getTax();
    }

    @Override
    public int updateStatus(String orderId) {
        JslOrderVo jslOrderVo = jslOrderMapper.selectJslOrderVoByOrderId(orderId);
        BigDecimal deduction = jslOrderVo.getDeduction();
        //取消订单返还余额
        if (deduction != null) {
            Long userId = jslOrderVo.getUserId();
            BigDecimal usermoney = jslUserMapper.selectMoneyByUserId(userId);
            BigDecimal add = usermoney.add(deduction);
            jslUserBalanceService.addBalance(5, deduction, orderId, userId, userId);
            jslUserMapper.updateUserMoneyById(add, userId);
        }
        //取消订单返还库存
        List<JslOrderGoods> jslOrderGoods = jslOrderGoodsMapper.selectOrderByOrderId(orderId);
        for (JslOrderGoods jsl : jslOrderGoods) {
            Integer goodsNum = jsl.getGoodsNum();
            GoodsAttrVo goodsAttrVo = jslGoodsAttrMapper.selectGoodsAttrVoByGoodsAttrId(jsl.getGoodsAttrId());
            Integer storeCount = goodsAttrVo.getStoreCount();
            Integer stock = goodsNum + storeCount;
            jslGoodsAttrMapper.updateStoreCountByGoodsIdAndAttrId(stock, jsl.getGoodsId(), jsl.getGoodsAttrId());
        }
        //待付款状态下取消订单返还代金券余额
        if(jslOrderVo.getCouponPrice().compareTo(new BigDecimal("0.00"))!=0 && jslOrderVo.getPayStatus()==0){
            JslCouponUseList couponUseList = jslCouponUseMapper.selectOne(new QueryWrapper<JslCouponUseList>().eq("order_id", orderId));

            if(couponUseList!=null){
                System.out.println(couponUseList.getCouponId());
                JslUserCoupon couponVo = jslUserCouponMapper.selectOne(new QueryWrapper<JslUserCoupon>().eq("id",couponUseList.getUserCouponId()));
                JslCoupon coupon = jslCouponMapper.selectOne(new QueryWrapper<JslCoupon>().eq("coupon_id", couponVo.getCouponId()));
                if(coupon.getCategory()==1){
                    couponVo.setRemAmount(couponVo.getRemAmount().add(jslOrderVo.getCouponPrice()));
                    couponVo.setIsSend(1);
                    jslUserCouponMapper.updateUserCoupon(couponVo);
                }
            }
        }
        jslOrderMapper.updateStatus(orderId);
        if(jslOrderVo.getPayStatus()==0){
            jslUserCouponMapper.updateCouponStatus(orderId);
        }
        return 1;
    }

    @Override
    public int updateOrderType(String orderId) {
        return jslOrderMapper.updateOrderType(orderId);
    }

    /**
     * 用户确认收货完后的代理机制
     *
     * @param inviteId 邀请人的id
     */
    public void award(String inviteId) {
        JslUser jslUser = this.jslUserMapper.selectById(inviteId);

        //一阶佣金比例
        String oneScale = "2";
        //二阶佣金比例
        String twoScale = "1";

        //最顶点的邀请人
        Long first = jslUser.getInviteId();
//        if ()
    }

    @Override
    public void aboutApply(String orderId,Long userId) {
        JslUserFareOrderApply apply = jslUserFareOrderApplyMapper.selectApplyByOrderId(orderId);
        JslOrderVo jslOrder = jslOrderMapper.selectJslOrderVoByOrderId(orderId);
        BigDecimal totalAmount = jslOrder.getTotalAmount();
        if(apply !=null){
            Long id = apply.getFareId();
            JslUserExtend jslUserExtend = jslUserExtendMapper.selectJslUserExtendById(id);
            if (jslUserExtend == null) {
                throw new ParamException(ConstantCode.PARAM_EXCEPTION.getCode(), "请前往我的-发票申请录入抬头信息");
            }
            // 根据当前用户判断是否为个人用户信息
            jslOrder.setFareTitle(
                    jslUserExtend.getFareType() == 1 ? jslUserExtend.getRealName() : jslUserExtend.getInvoiceTitle());
            //向用户已申请发票表插入信息 'jsl_user_fare_applied'
            JslUserFareApplied jslUserFareApplied = new JslUserFareApplied();
            jslUserFareApplied.setUserId(userId);
            jslUserFareApplied.setExtendId(jslUserExtend.getId());
            //应支付金额
            jslUserFareApplied.setFareMoney(totalAmount);
            if (jslUserExtend.getFareType() == 1) jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setAddress(jslUserExtend.getAddress());
            jslUserFareApplied.setEmail(jslUserExtend.getEmail());
            jslUserFareApplied.setBank(jslUserExtend.getBank());
            jslUserFareApplied.setBankAccount(jslUserExtend.getBankAccount());
            jslUserFareApplied.setIdCard(jslUserExtend.getIdCard());
            jslUserFareApplied.setInvoiceTitle(jslUserExtend.getInvoiceTitle());
            jslUserFareApplied.setRealName(jslUserExtend.getRealName());
            jslUserFareApplied.setPhone(jslUserExtend.getPhone());
            jslUserFareApplied.setTaxpayer(jslUserExtend.getTaxpayer());
            jslUserFareApplied.setFareType(jslUserExtend.getFareType());
            jslUserFareAppliedMapper.insert(jslUserFareApplied);
            //修改jsl_user_fare_order_apply表中的fare_apply_id字段
            JslUserFareOrderApply userFareOrderApply=new JslUserFareOrderApply();
            userFareOrderApply.setId(apply.getId());
            userFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            jslUserFareOrderApplyMapper.updateById(userFareOrderApply);
            //向用户申请发票订单表插入数据 'jsl_user_fare_order_apply'
           /* JslUserFareOrderApply jslUserFareOrderApply = new JslUserFareOrderApply();
            //判断是否是多个订单,多个订单不向数据库存入orderId
            if (jslOrder.getOrderId().contains(",")) {
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalAmount);
                jslUserFareOrderApply.setFareId(id);
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
                jslUserFareOrderApply.setFareId(jslUserExtend.getId());
                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            } else {
                // 配置接收发票的邮箱
                jslOrder.setEmail(jslUserExtend.getEmail());
                jslUserFareOrderApply.setUserId(userId);
                jslUserFareOrderApply.setOrderMoney(totalAmount);
                jslUserFareOrderApply.setFareId(id);
                jslUserFareOrderApply.setOrderId(jslOrder.getOrderId());
                jslUserFareOrderApply.setCreateTime(LocalDateTime.now());
                jslUserFareOrderApply.setFareApplyId(jslUserFareApplied.getFareId());
            }
            jslUserFareOrderApplyMapper.insert(jslUserFareOrderApply);*/
        }
    }

    /**
     * 创建账号一个月之内未下单
     */
    @Override
    public List<JslOrder> selectJslOrderNearMonth(Long userId, LocalDateTime addTime) {
        return jslOrderMapper.selectJslOrderNearMonth(userId,addTime);
    }
}
